package com.lzx.shop.controller;

import com.lzx.shop.service.CategoryService;
import com.lzx.shop.service.ProductService;
import com.lzx.shop.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 刘正星
 * @version 1.0.0
 * @ClassName MainController.java
 * @Description TODO
 * @createTime 2021年03月19日 22:51:00
 */
@Controller
@RequestMapping("/views")
public class MainController {

    @Autowired
    private UserService userService;
    @Autowired
    private CategoryService categoryService;

    @Autowired
    private ProductService productService;
    @GetMapping("/console.html")
    public String console(Model model){

       Integer userCount = userService.count();

       Integer categoryCount = categoryService.count();

       Integer productCount = productService.count();

       Map<String,Integer> statistics = new HashMap<>();
       //数据统计
       statistics.put("userCount",userCount);
       statistics.put("categoryCount",categoryCount);
       statistics.put("productCount",productCount);

       model.addAttribute("statistics",statistics);
        return "views/console";
    }

    @GetMapping("/users.html")
    public String users(Model model){
        return "views/users";
    }

    @GetMapping("/store.html")
    public String store(Model model){
        return "views/store";
    }

    @GetMapping("/category.html")
    public String category(Model model){
        return "views/category";
    }

    @GetMapping("/product.html")
    public String product(Model model){
        return "views/product";
    }

    @GetMapping("/productDetail.html")
    public String productDetail(Model model){
        return "views/productDetail";
    }

    @GetMapping("/order.html")
    public String order(){
        return "views/order";
    }

    @GetMapping("/paymentRecord.html")
    public String paymentRecord(){
        return "views/paymentRecord";
    }

}
